<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.keywords" placeholder="用户名称、用户手机号、提现帐号" clearable style="width: 300px"></el-input>
      </el-form-item>
      <el-form-item label="打款方式">
				<el-select v-model="dataForm.accType" placeholder="打款方式">
          <el-option label="全部" value="" ></el-option>
					<el-option label="银行卡" value="0" ></el-option>
					<el-option label="微信" value="1" ></el-option>
					<el-option label="手动打款" value="2" ></el-option>
          <el-option label="支付宝" value="3" ></el-option>
				</el-select>
			</el-form-item>
      <el-form-item label="提现状态">
				<el-select v-model="dataForm.cashStatus" placeholder="提现状态">
					<el-option label="全部" value="" ></el-option>
          <el-option label="提现失败" value="0" ></el-option>
					<el-option label="提现成功" value="1" ></el-option>
					<el-option label="提现中" value="2" ></el-option>
          <el-option label="待审核" value="3" ></el-option>
          <el-option label="审核不通过" value="5" ></el-option>
				</el-select>
			</el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button @click="
          dataForm.accType = ''
          dataForm.cashStatus = ''
          dataForm.status = ''
          dataForm.keywords = ''
          getDataList()">重置</el-button>
        <el-badge :value="this.num" class="item">
          <el-button size="small" @click="unaudited()">待审核</el-button>
        </el-badge>
        <el-button icon="el-icon-download" type="primary" @click="excel()">导出</el-button>
        <el-button v-if="isAuth('user:cashAudit:queryWeekCashWithdrawalList')" type="primary" @click="weekcashwithdrawal()">周提现</el-button>
        <el-button type="primary" @click="month()">月提现</el-button>
        <el-tag>平台未提现余额:{{moneyNum[1]}}</el-tag>
        <el-tag type="success">推广余额:{{moneyNum[2]}}</el-tag>
        <el-tag type="info">联盟店销售余额:{{moneyNum[0]}}</el-tag>
        <!-- <span style="font-size: 17px">平台未提现余额:{{moneyNum[1]}}</span>&nbsp;&nbsp;
        <span style="font-size: 17px">推广余额:{{moneyNum[2]}}</span>&nbsp;&nbsp;
        <span style="font-size: 17px">联盟店销售余额:{{moneyNum[0]}}</span> -->
        <!-- <el-button v-if="isAuth('generator:businesswithrecord:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button> -->
        <!-- <el-button v-if="isAuth('generator:businesswithrecord:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <!-- <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column> -->
      <el-table-column
        prop="withUserName"
        header-align="center"
        align="center"
        label="用户名称">
      </el-table-column>
      <el-table-column
        prop="username"
        header-align="center"
        align="center"
        label="用户手机号">
      </el-table-column>
      <el-table-column
        prop="accType"
        header-align="center"
        align="center"
        label="帐号类型">
        <template slot-scope="scope">
          <span v-if="scope.row.accType == 0">银行卡</span>
          <span v-if="scope.row.accType == 1">微信</span>
          <span v-if="scope.row.accType == 2">手动</span>
          <span v-if="scope.row.accType == 3">支付宝</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="accountNo"
        header-align="center"
        align="center"
        label="提现帐号">
      </el-table-column>
      <el-table-column
        prop="money"
        header-align="center"
        align="center"
        label="提现金额">
        <template slot-scope="scope">
          <span v-if="scope.row.money != null">￥ {{scope.row.money}}</span>
          <span v-if="scope.row.money == null">￥ 0</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="cashStatus"
        header-align="center"
        align="center"
        label="提现状态">
        <template slot-scope="scope">
          <span v-if="scope.row.cashStatus == 0">提现失败</span>
          <span v-if="scope.row.cashStatus == 1">提现成功</span>
          <span v-if="scope.row.cashStatus == 2">提现中</span>
          <span v-if="scope.row.cashStatus == 3">待审核</span>
          <span v-if="scope.row.cashStatus == 5">审核不通过</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="提现时间">
      </el-table-column>
      <el-table-column
        prop="count"
        header-align="center"
        align="center"
        label="周内提现次数">
      </el-table-column>
      <el-table-column
        prop="weekMoney"
        header-align="center"
        align="center"
        label="周内提现总金额">
        <template slot-scope="scope">
          <span v-if="scope.row.weekMoney != null">￥ {{scope.row.weekMoney}}</span>
          <span v-if="scope.row.weekMoney == null">￥ 0</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="cashSatus"
        header-align="center"
        align="center"
        label="审核">
        <template slot-scope="scope">
          <!-- <el-button size="small" type="warning" icon="check" @click="handleAdopt(scope.row.id)" v-if="(scope.row.cashSatus)== 3">通过</el-button>
          <el-button size="small" type="danger" icon="edit" @click="handleNoAdopt(scope.row.id)" v-if="(scope.row.cashSatus)== 3">不通过</el-button> -->
          <el-button size="small" type="warning" icon="check" @click="pass(scope.row.withRecordId, 1, scope.row.withUserType, scope.row.money, scope.row.withUserId, scope.row.orderNo, scope.row.accType)" v-if="(scope.row.cashStatus)== 3">通过</el-button>
          <el-button size="small" type="danger" icon="edit" @click="pass(scope.row.withRecordId, 2, scope.row.withUserType, scope.row.money, scope.row.withUserId, scope.row.orderNo, scope.row.accType)" v-if="(scope.row.cashStatus)== 3">不通过</el-button>
          <span v-if="scope.row.cashStatus == 0">提现失败</span>
          <span v-if="scope.row.cashStatus == 1">提现成功</span>
          <span v-if="scope.row.cashStatus == 2">提现中</span>
          <span v-if="scope.row.cashStatus == 4">已审核</span>
          <span v-if="scope.row.cashStatus == 5">审核不通过</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.withRecordId)">详情</el-button>
          <el-button type="text" size="small" @click="addOrUpdateHandle1(scope.row.withUserId)">{{scope.row.withUserType === '1' ? '推广收益' : (scope.row.withUserType === '4' ? '推广收益' : '商家收益')}}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList1"></add-or-update>
    <merchantincome v-if="addOrUpdateVisible" ref="merchantincome" @refreshDataList="getDataList1"></merchantincome>
    <weekcashwithdrawal v-if="addOrUpdateVisible" ref="weekRef" @refreshDataList="getDataList"></weekcashwithdrawal>
    <month v-if="addOrUpdateVisible" ref="monthRef" @refreshDataList="getDataList"></month>
  </div>
</template>

<script>
  import AddOrUpdate from './businesswithrecord-add-or-update'
  import merchantincome from './merchantIncome'
  import weekcashwithdrawal from './weekcashwithdrawal'
  import month from './monthcashwithdrawal'
  export default {
    data () {
      return {
        dataForm: {
          keywords: '',
          accType: '',
          cashStatus: '',
          status: ''
        },
        moneyNum: [],
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        num: 0
      }
    },
    components: {
      AddOrUpdate,
      weekcashwithdrawal,
      month,
      merchantincome
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/user/cashAudit/queryCashAuditList'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keywords': this.dataForm.keywords,
            'accType': this.dataForm.accType,
            'cashStatus': this.dataForm.cashStatus,
            'status': this.dataForm.status
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.moneyNum = []
            this.dataList = data.data.list[0].cashAuditListVO
            this.moneyNum.push(data.data.list[0].allMoney)
            this.moneyNum.push(data.data.list[0].notExtract)
            this.moneyNum.push(data.data.list[0].commissionMoney)
            this.totalPage = data.data.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
        // 提现审核
        this.$http({
          url: this.$http.adornUrl('/user/cashAudit/queryWithRecordCount'),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.num = data.data
          } else {
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 周提现
      weekcashwithdrawal () {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.weekRef.init(1)
        })
      },
      // 月提现
      month () {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.monthRef.init(2)
        })
      },
      // 商家收益
      addOrUpdateHandle1 (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.merchantincome.init(id)
        })
      },
      // 是否通过审核
      pass (id, type, withUserType, money, withUserId, orderNo, accType) {
        if (type === 2) {
          this.$prompt('请输入不通过信息', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            inputType: 'textarea'
          }).then(({ value }) => {
            if (value === null || value === '') {
              this.$message.error('审核内容不能为空！')
              return false
            }
            this.$http({
              url: this.$http.adornUrl('/user/cashAudit/modifyCashAudit'),
              method: 'post',
              data: this.$http.adornData({
                'id': id,
                'type': type,
                'withUserType': withUserType,
                'money': money,
                'withUserId': withUserId,
                'noPass': value,
                'orderNo': orderNo,
                'accType': accType
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.getDataList()
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '取消输入'
            })
          })
        }
        if (type === 1) {
          this.$confirm(`确定进行通过操作?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.$http({
              url: this.$http.adornUrl('/user/cashAudit/modifyCashAudit'),
              method: 'post',
              data: this.$http.adornData({
                'id': id,
                'type': type,
                'withUserType': withUserType,
                'money': money,
                'withUserId': withUserId,
                'accType': accType
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.getDataList()
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          })
        }
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.withrecordid
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/generator/businesswithrecord/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      excel () {
        window.location.href = this.$http.adornUrl(`/user/cashAudit/cashAuditExcel?token=${this.$cookie.get('token')}&keywords=${this.dataForm.keywords}&accType=${this.dataForm.accType}&cashStatus=${this.dataForm.cashStatus}`)
      },
      // 待审核
      unaudited () {
        this.dataForm.status = 0
        this.getDataList()
      }
    }
  }
</script>
